<template>
	<block>
		<hxt-layout id="hxt-layout" title="去水印" svc="img" initTitle="去水印加载失败" @initPage="initPage">
			<view class="hxt-flex-column" style="background-color: #fff;">
				<view class="hxt-flex-fill" style="overflow: hidden;">
					<view style="background-color: #F5F5F5;padding: 30rpx;margin: 20rpx;border-radius: 15rpx;">
						<view class="padding-bottom">
							<text class="text-red">*</text>
							<text style="font-weight: bold;">分享链接</text>
						</view>
						<view class="inputborder">
							<hxt-input :border="false" v-model="shareUrl" placeholder="请输入视频的页面网址">
							</hxt-input>
						</view>
						<!-- <view v-if="!!formERR.valueERR"
								style="color:#ee0a24;font-size:24rpx;text-align: right;margin-top: 10rpx;">
								{{formERR.valueERR}}
							</view> -->
					</view>
					<view class="hxt-flex" style="margin: 0 20rpx;justify-content: space-between;">
						<button class="cu-btn" @click="zhantie">粘贴</button>
						<button class="cu-btn bg-blue shadow" @click="submit">提交</button>
					</view>

				</view>
				<van-tabbar :active="active" @change="change" :safe-area-inset-bottom="false" :fixed="false">
					<van-tabbar-item v-for="(item,index) in urlList" :name="item.value" :key="index" :icon="item.icon"
						v-if="item.show">{{item.text}}</van-tabbar-item>
				</van-tabbar>
			</view>
		</hxt-layout>
		<hxt-loading id="hxt-loading"></hxt-loading>
	</block>
</template>

<script>
	import hxt from "@/utils/hxt.js"
	export default {
		data() {
			return {
				list: [],
				urlList: [{
					text: '快手',
					p: '故梦API',
					icon: 'setting-o',
					value: 0,
					url: 'https://api.suyanw.cn/api/dykstjjx.php',
					type: 'json',
					show: true,
				}, {
					text: '抖音',
					p: '故梦API',
					icon: 'setting-o',
					value: 1,
					url: 'https://api.gumengya.com/Api/DouYin',
					type: 'json',
					show: true
				}],
				shareUrl: '',
				active: 0,
			}
		},
		onShow: function(e) {},
		methods: {
			initPage: function(e) { //初始化事件

			},
			change: function(e) {
				this.active = e.detail;
				this.shareUrl = "";
			},
			zhantie:function(){
				var _this=this;
				wx.getClipboardData({
				  success (res){
				    _this.shareUrl=res.data;
				  }
				})
			},
			show: function(url) {
				var _this = this,
					list = _this.list;
				wx.previewImage({
					current: url, // 当前显示图片的http链接
					urls: list // 需要预览的图片http链接列表
				});
			},
			submit:function(){
				var _this=this,obj=_this.urlList[_this.active];
				if(!hxt.trim(_this.shareUrl))return hxt.Notify({
								type: 'warning',
								message: '请输入链接'
							});
				hxt.post({
					url: obj.url,
					data: {url:_this.shareUrl},
					ok: function(res) {
						if (res.data.code != 200) {
							hxt.Notify({
								type: 'danger',
								message: '加载失败：' + res.data.msg + '，请稍后重试！'
							});
							return;
						};
						var data = res.data.data.url;
					},
					fail: function(res) {
						hxt.loading(false);
						hxt.Notify({
							type: 'danger',
							message: '加载失败：' + res.errMsg + '，请稍后重试！'
						});
					}
				});
			}
		}
	}
</script>

<style>
	.inputborder {
		border: 2rpx solid #e5e5e5;
		border-radius: 8rpx;
		background-color: #fff;
		padding: 1rpx 10rpx;
	}

	.van-cell {
		padding: 10rpx !important;
	}
</style>
